/*
 * Copyright 2009-2010 Belmont Software Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.belmont.backup;

import java.util.*;
import java.io.*;
import org.json.*;

public interface IBackupServer {
    /**
     * Initiate a session with the server. user can be any string
     * that describes the user of the server. For network sessions,
     * authentication is done using http digest authentication. The
     * returned value is a session string that should be passed on
     * to all subsequent requests to the server.
     */
    String connect(String protocolVersion, String uuid, String host, String osname, String osversion, String user) throws IOException;

    /**
     * Refreshes any config information from the server.
     */
    void refresh() throws IOException;

    Config getConfig();

    /**
     * Terminates all activity for this session.
     */
    void disconnect(String session) throws IOException;


    /**
     * Initiate a backup operation
     */
    JSONObject startBackup(String session, String path) throws IOException, JSONException;

    /**
     * Returns the available versions for this session. The keys are
     * the paths available and the value is a JSONArray of JSONObject
     * objects with keys name and date.
     */
    JSONObject getAvailableVersions(String session) throws IOException, JSONException;



    JSONObject checkFiles(String session, String backupid, String path, JSONObject fileRequest) throws IOException, JSONException;

    /**
     * Sends a file to the server with the information about the file
     * contained in req.
     */
    void sendFile(String session, String digest,
		  String name, long length, long offset,
		  InputStream in) throws IOException, InterruptedException;

    /**
     * Gets a file identified by req from the server.
     */
    void getFile(String session,
		 String digest,
		 String name,
		 long length,
		 long offset,
		 OutputStream out) throws IOException, InterruptedException;

    /**
     * Cancels an ongoing backup operation.
     */
    void cancelBackup(String session, String path) throws IOException;

    /**
     * Commmits an ongoing backup operation for this session and path.
     */
    void commitBackup(String session, String backupid, String path) throws IOException;
}
